/***
 * 该文件的主要功能：生成Token、校验Token
 */

var jwt = require('jsonwebtoken');
var signkey = 'hcj'; // 设置密钥

exports.setToken = function(username,userid){
    return new Promise((resolve,reject)=>{
        const token = jwt.sign({
            name:username,
            _id:userid
        },signkey,{ expiresIn:'0.01h' });
        resolve(token);
    })
}

exports.verToken = function(token){
    return new Promise((resolve,reject)=>{
        var info = jwt.verify(token.split(' ')[1],signkey);
        resolve(info);
    })
}
